Skip to content

Explicit check for empty arrays before using Array.every() - #339

Closed
Rusola wants to merge 1 commit into
hexlet-basics:mainfrom
Rusola:branch1
Closed

Explicit check for empty arrays before using Array.every()#339
Rusola wants to merge 1 commit into
hexlet-basics:mainfrom
Rusola:branch1

Conversation

@Rusola

@Rusola Rusola commented Apr 16, 2026

Copy link
Copy Markdown

This change adds an explicit check for empty arrays before using Array.every().
Reason:
In JS/TS, Array.prototype.every() returns true for empty arrays.
Fix helps for scenarios like:
const a = [];
const b = [1, 2, 3];

@fey

fey commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Thanks for the contribution, but this check can't be triggered here.

Point is declared as a fixed-length tuple:

export type Point = [number, number, number];

so p1.length and p2.length are both typed as 3 — the p1.length !== p2.length branch is unreachable and only adds dead code to the teacher's solution. Your point about every() returning true for an empty array is correct in general, but this lesson is specifically about tuples guaranteeing the length at the type level: an empty Point cannot be constructed in the first place.

Also, the added blank line has trailing whitespace, which would fail make code-lint (biome).

Closing this one, but thanks for looking into the lesson — issues and PRs on the content are always welcome.

@fey fey closed this Aug 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants